package cn.echo.controller;

import cn.echo.entity.User;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2017/5/17.
 */
@Controller
//@RestController 如果用这个不用@Controller下面的接口可以不用写@ResponseBody
@RequestMapping("app/user")
public class UserAppController {

    @ResponseBody
    @RequestMapping("list")
    public List<User> userList(){

        List<User> userList = new ArrayList<User>();
        userList.add(new User("1","zhangsan","123456","男"));
        userList.add(new User("2","zhangsan1","123456","男"));
        userList.add(new User("3","zhangsan2","123456","男"));
        userList.add(new User("4","zhangsan3","123456","男"));
        userList.add(new User("5","zhangsan4","123456","男"));
        userList.add(new User("6","zhangsan5","123456","男"));

        ObjectMapper objectMapper = new ObjectMapper();
        String json = "";
        try {
           json =  objectMapper.writeValueAsString(userList);
        } catch (JsonProcessingException e) {
            e.printStackTrace();
        }
        return userList;
    }
}
